package com.aabte.feignhttp.feignhttpclient;

import feign.Feign;
import org.springframework.beans.factory.FactoryBean;

/**
 * @author Daniel
 */
public class FeignHttpApiFactoryBean implements FactoryBean<Object> {

    private String name;

    private Feign.Builder httpBuilder;

    private String baseUrl;

    private String path;

    private String type;

    private Class<?> serviceClass;

    @Override
    public Object getObject() throws Exception {
        // mybatis中的动态代理其实在feign提供的API中已经实现了
        return httpBuilder.target(serviceClass, baseUrl + path);
    }

    @Override
    public Class<?> getObjectType() {
        return serviceClass;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

    public Feign.Builder getHttpBuilder() {
        return httpBuilder;
    }

    public void setHttpBuilder(Feign.Builder httpBuilder) {
        this.httpBuilder = httpBuilder;
    }

    public Class<?> getServiceClass() {
        return serviceClass;
    }

    public void setServiceClass(Class<?> serviceClass) {
        this.serviceClass = serviceClass;
    }

    public String getBaseUrl() {
        return baseUrl;
    }

    public void setBaseUrl(String baseUrl) {
        this.baseUrl = baseUrl;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
}